package com.ruoyi.framework.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 拦截器配置
 */
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Bean
    public LogcostInterceptor loginBaseInterceptor(){
        return new LogcostInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginBaseInterceptor())
                //添加需要验证登录用户操作权限的请求
                .addPathPatterns("/api/**")
                //这里add为“/**”,下面的exclude才起作用，且不管controller层是否有匹配客户端请求，拦截器都起作用拦截
//                .addPathPatterns("/hello")
                //如果add为具体的匹配如“/hello”，下面的exclude不起作用,且controller层不匹配客户端请求时拦截器不起作用
        //这里可以用registry.addInterceptor添加多个拦截器实例，后面加上匹配模式
        .excludePathPatterns("/api/login/loginPassword")
                .excludePathPatterns("/api/login/addCustomer")
                .excludePathPatterns("/api/login/checkLoginPhone")
                .excludePathPatterns("/api/login/getPhoneCode");
//        .excludePathPatterns("/api/login/loginP");
        super.addInterceptors(registry);//最后将register往这里塞进去就可以了
    }

}
